#!/bin/sh
case "$1" in
  start)
    if [ "$(kernopt run_stresstest)" = 1 ]; then
      ssid=$(kernopt test_ssid)
      [ "$ssid" = 1 ] && ssid=  # if given but blank, consider it not given
      [ -n "$ssid" ] && burnin-wifi-setup "$ssid"
      export MAX_BANDWIDTH=$(kernopt test_bw)
      export DONT_ABORT=1
      echo "run_stresstest is set: running stresstest on boot."
      (wait-until-created /tmp/time.synced && stresstest) &
    else
      echo "run_stresstest is not set: skipping."
    fi
    ;;
  stop)
    pkillwait -x stresstest
    ;;
  restart)
    $0 stop; $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac
